import React, { PureComponent } from 'react';
import { Table } from 'antd';
import api from '../../../../../../api/api';

const frequencyData = [
  { id: 1, name: '每日一次' },
  { id: 2, name: '每日两次' },
  { id: 3, name: '每日三次' },
  { id: 4, name: '每日四次' },
  { id: 5, name: '每夜一次' },
  { id: 6, name: '每周一次' },
];
const columns = [{
  title: '通用名(商品名)',
  dataIndex: 'commonName',
  key: 'commonName',
  render: (text, record, index) => {
    return (<div>{record.commonName}{ record.productName?<span>({record.productName})</span>:null}</div>)
  }
}, {
  title: '用法',
  dataIndex: 'frequency',
  key: 'frequency',
  render: (text, record, index) => {
    let data = frequencyData.filter(item => item.id === record.frequency)
    return (<div>{ data&&data.length>0?data[0].name:undefined }</div>)
  }
}, {
  title: '用量',
  dataIndex: 'useAmount',
  key: 'useAmount',
  render: (text, record, index) => {
    return (<div>一次{record.useAmount}{ record.minimumUnit }</div>)
  }
}, {
  title: '规律用量',
  dataIndex: 'useTips',
  key: 'useTips',
  render: (text, record, index) => {
    return (<div>{record.amount}{ record.packageUnit }</div>)
  }
}];
export default class UseMedicationComponent extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      columns: [],
      data: []
    }
  }
  componentDidMount() {
    this.getUseMedicationFun();
  }
  getUseMedicationFun = async () => {
    const { patientId } = this.props;
    const { drugs } = await api.getRegularMedication(patientId);
    this.setState({
      data:drugs
    })
  }
  render() {
    return (
      <div>
        <Table className="sickTable" columns={columns} dataSource={this.state.data} pagination={ false } rowKey='key'/>
      </div>
    );
  }
}
